import Taro from '@tarojs/taro';
import * as sdk from './fetch';

/**
 * 查询游戏信息接口
 * @param params
 * @returns
 */
async function getGameIpConfigInfo(params = {}): Promise<any> {
  let result = await sdk.get<any>(`doll/getInfo`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 是否是新人保障
 * @param params
 * @returns
 */
async function userIsNewComer(params = {}): Promise<any> {
  let result = await sdk.post<any>(`game-base-config/isNewcomer`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 抓取抽奖
 * @param params
 */
async function drawLottery(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`doll/play`, {
      ...params,
    });
  } catch (e) {
    result = e;
    if (e.code == 'K-000001') {
      Taro.showToast({
        title: '操作失败',
        icon: 'none',
      });
    }
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 批量领取奖励
 * @param params
 */
async function claimRewards(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`customercollection/batchReceive`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getGameIpConfigInfo,
  userIsNewComer,
  drawLottery,
  claimRewards,
};
